/**
 * ColorSensor
 *
 * Authors: Bruna and Bruno
 * Date: Jun, 09 2012
 **/

#ifndef ColorSensor_h
#define ColorSensor_h

#include <Arduino.h>
#include <Wire.h>

typedef enum {
    _RED=0, _GREEN=1, _LILAC=2, _YELLOW=3, _NONE=4
} Color;

class ColorSensor {
    public:
        ColorSensor(int _ledPin, int _samples);
        void begin();
        Color read();
        void calibrate();
        void ledOn();
        
    private:
        int ledPin;
        int samples;
    
        unsigned char colorCap[4]; // values must be between 0 and 15
        unsigned int colorInt[4]; // max value for these is 4095
        unsigned int colorData[4]; // This is where we store the RGB and C data values
        signed char colorOffset[4]; // Stores RGB and C offset values
        
        float normalizedRGB[2]; // This is where we store the RGB normalized data values
        
        void init();
        void reset();
        void getNormalizedRGB();
        void getRGBC();
        void measure();
        void calibrateClear();
        void calibrateColor();
        void calibrateCapacitors();
        
        void writeRegister(unsigned char data, unsigned char address);
        unsigned char readRegister(unsigned char address);
        void writeRegisterInt(int address, int gain);
        int readRegisterInt(unsigned char address);
};
#endif